package com.haidada.tk.pojo;


import com.haidada.tk.utils.DateUtils;
import lombok.Data;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 用户
 * @author Hai
 */
@Entity
@Table(name = "t_user")
@Data
public class User {

    @Id
    private Long id;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createdTime = new Date();

    @Column(columnDefinition = "varchar(64) not null comment '微信id'")
    private String openId;

    @Column(columnDefinition = "varchar(64) comment '密码'")
    private String password;

    @Column(columnDefinition = "varchar(200) comment '头像地址'")
    private String headImage;

    @Column(columnDefinition = "varchar(50) comment '手机号码'")
    private String mobile;

    @Column(columnDefinition = "bit(1) not null comment '是否VIP,1是，0不是'")
    private boolean gift = false;

    @Column(columnDefinition = "bit(1) not null comment '1删除，0正常'")
    private boolean deleted = false;

    @Column(columnDefinition = "int  comment '打赏总数'")
    private int giftQuantity;

    @Column(columnDefinition = "int  comment '打赏总数'")
    private BigDecimal giftOutlay;

    @Column(columnDefinition = "datetime comment '最后登陆时间'")
    private Date lastLoginTime;

    /**
     * 默认女
     */
    @Column(columnDefinition = "int(1) comment '性别,0未知，1男，2女'")
    private Integer sex = 2;

    @Column(columnDefinition = "bit(1) not null comment '是否VIP,1是，0不是'")
    private boolean vip = false;

    @Column(columnDefinition = "date comment 'vip开始时间'")
    private Date vipStartDate;

    @Column(columnDefinition = "date comment 'vip结束时间'")
    private Date vipEndDate;

    /**
     * 检查是否vip
     *
     * @return 是否vip
     */
    public boolean checkVIP() {
        Date now = DateUtils.getDayBegin();
        return vip && vipEndDate.getTime() >= now.getTime();
    }

}
